package de.baumann.browser.activitys.duobao

import android.content.Context
import android.content.Intent
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.adapter.CYJLAdapter
import de.baumann.browser.api.net.vo.duobao.CYJL
import de.baumann.browser.api.net.vo.duobao.ZJXX
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.duobao.IJieXiaoDetailView
import de.baumann.browser.present.duobao.JieXiaoDetailPresenter
import de.baumann.browser.units.GlideImageLoader
import de.baumann.browser.views.dialog.ZJXXDialog
import kotlinx.android.synthetic.main.activity_can_yu_record.*
import kotlinx.android.synthetic.main.activity_duo_bao_detail.*
import kotlinx.android.synthetic.main.activity_jie_xiao_detail.*
import kotlinx.android.synthetic.main.include_tool_bar_2.*

class JieXiaoDetailActivity : BaseOdinActivity<IJieXiaoDetailView, JieXiaoDetailPresenter>(), IJieXiaoDetailView {


    companion object {
        fun startJieXiaoDetailActivity(context: Context, id: String, code: String) {
            context.startActivity(Intent(context, JieXiaoDetailActivity::class.java).apply {
                putExtra("id", id)
                putExtra("code", code)
            })
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_jie_xiao_detail
    }

    override fun getTitleText(): String {
        return "${intent.getStringExtra("code")} 期"
    }

    override fun getBackIcon(): Int {
        return R.drawable.ic_back
    }


    private lateinit var cyjlAdapter: CYJLAdapter

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        jxDetailBanner.setImageLoader(GlideImageLoader())
        cyjlAdapter = CYJLAdapter()
        jxcyjl.adapter = cyjlAdapter

        cyjlAdapter.setOnItemClickListener { adapter, view, position ->
            val jl = cyjlAdapter.getItem(position)
            CanYuDetailActivity.startCanYuDetailActivity(mContext, jl!!.participationInfoId)
        }
        allJXCanYu.setOnClickListener {
            CanYuRecordActivity.startCanYuRecordActivity(mContext, getId())
        }

        zjyhxx.setOnClickListener {
            presenter?.zjxx()
        }
    }

    override fun initData() {
        presenter?.detail()
        presenter?.cyjl()
    }

    override fun createPresenter(): JieXiaoDetailPresenter {
        return JieXiaoDetailPresenter()
    }

    override fun createView(): IJieXiaoDetailView {
        return this
    }

    override fun getId(): String {
        return intent.getStringExtra("id")
    }

    override fun setBanner(list: List<String>) {
        jxDetailBanner.setImages(list)
        jxDetailBanner.start()
    }

    override fun setTitle(title: String) {
        jxDetlMingcheng.text = title
    }

    override fun setZJTX(tx: String) {
        OdinGlideModule.loadWithCropAndCircle(mContext, tx, zjHead, R.drawable.icon_head)
    }

    override fun setZJMC(mc: String) {
        zjName.text = mc
    }

    override fun setCYRS(rs: String) {
        cyrs.text = "本期参与人数：${rs}人"
    }

    override fun setKJSJ(sj: String) {
        kjsj.text = "开奖时间：${sj}"
    }

    override fun setXYHM(hm: String) {
        xyhm.text = "幸运号码：${hm}"
    }

    override fun setList(list: List<CYJL>) {
        cyjlAdapter.setNewData(list)
    }

    override fun setZJXX(zjxx: ZJXX) {
        ZJXXDialog(mContext).setData(zjxx).show()
    }
}